
class Camara{
public:
    float x,y,z;
    float alpha,beta,gamma=0;
    float d,fov;
    float l,r,b,t,n,f;
    float mvspd,mtspd;
    float dis;
    const Uint8* keystate;

    Camara(
        float _x,float _y,float _z,
        float _alpha,float _beta
    ):
        x(_x),y(_y),z(_z),fov(75),d(0.05),
        n(0.05),f(64.0),dis(6.0),
        alpha(_alpha),beta(_beta),
        mvspd(4.8/fps),mtspd(180.0/fps) 
    {
        r=tan(fov*pi/360.0)*2.0*(d>0.0?d:-d);l=-r;t=r*9.0/16.0;b=-t;
    };
    Camara():Camara(0.0,0.0,0.0,0.0,0.0){};

    void update(SDL_Event &e){
        //键盘操作更新相机朝向和原点矩
        keystate=SDL_GetKeyboardState(NULL);
        if(keystate[SDL_SCANCODE_W     ])/*    w    */{  beta-=mtspd;        }
        if(keystate[SDL_SCANCODE_S     ])/*    s    */{  beta+=mtspd;        }
        if(keystate[SDL_SCANCODE_A     ])/*    a    */{ alpha+=mtspd;        }
        if(keystate[SDL_SCANCODE_D     ])/*    d    */{ alpha-=mtspd;        }
        if(keystate[SDL_SCANCODE_SPACE ])/*  space  */{   dis+=mvspd*dis/7.0;}
        if(keystate[SDL_SCANCODE_LSHIFT])/*  lshift */{   dis-=mvspd*dis/7.0;}
        //限制变量范围
        dis=dis<5.0?5.0:dis>12.0?12.0:dis;
        alpha-=alpha>=360.0?360.0: 0.0;
        alpha+=alpha<   0.0?360.0: 0.0;
         beta = beta>= 90.0? 90.0:beta;
         beta = beta<- 90.0?-90.0:beta;
        //计算修改位置
        x=-dis*cos(beta*pi/180.0)*sin(alpha*pi/180.0);
        y=-dis*sin(beta*pi/180.0);
        z=-dis*cos(beta*pi/180.0)*cos(alpha*pi/180.0);
    }
};

